import { deleteDocuments, addOneDocument, lookDocuments, updateOneDocument } from '@/api/document'

const getDefaultState = () => {}

const state = getDefaultState()

const mutations = {}

const actions = {
  // 条件查询
  async lookDocuments({ state }, document) {
    return new Promise((resolve, reject) => {
      lookDocuments(document)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 添加一条资讯
  async addOneDocument({ state }, document) {
    return new Promise((resolve, reject) => {
      addOneDocument(document)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 修改资讯
  async updateOneDocument({ state }, document) {
    return new Promise((resolve, reject) => {
      updateOneDocument(document)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 批量删除资讯
  async deleteDocuments({ state }, ids) {
    return new Promise((resolve, reject) => {
      deleteDocuments(ids)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
}
